
/* Includes ------------------------------------------------------------------*/
#include "pm25.h"

int parsePM25Data(char* data, int length)
{
    int16_t checksum = 0;
    int i = 0;
    if( length != 32)
    {
        return -1;
    }

    for( i = 0; i < length - 2; i++)
    {
         checksum += *( data + i);
    }

    if((checksum & 0xFF) != *( data + length - 1))
    {
        return -1;
    }

    if(((checksum >>8) & 0xFF) != *( data + length - 2))
    {
        return -1;
    }
    
    return (data[12]*256+data[13]);
}
